package com.wkg;

import java.util.concurrent.TimeUnit;

public class Test_103 {
    public static void main(String[] args) {
        Object object = new Object();
        Thread t1 = new Thread(() -> {
            while (true) {
                synchronized (object) {
                    System.out.println("执行wait之前");
                    try {
                        object.wait();  //当wait时会自动释放掉锁资源
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.println("唤醒wait之后");
                    System.out.println("===========================");
                }

            }
        });

        Thread t2 = new Thread(() -> {
            while (true) {
                System.out.println("执行notifyAll之前");
                synchronized (object) {
                    try {
                        object.notifyAll();
                        System.out.println("执行notifyAll之后");
                        TimeUnit.SECONDS.sleep(1);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }

        });

        t1.start();
        t2.start();

    }
}

